﻿using System;
using System.Threading;

// 定义嘀嗒事件和响铃事件的参数类
public class TickEventArgs : EventArgs
{
    public DateTime CurrentTime { get; set; }
}

public class AlarmEventArgs : EventArgs
{
    public string AlarmMessage { get; set; }
}

// 定义闹钟类
public class AlarmClock
{

    public event EventHandler<TickEventArgs> Tick;
    public event EventHandler<AlarmEventArgs> Alarm;

    private DateTime _alarmTime;

    public AlarmClock(DateTime alarmTime)
    {
        _alarmTime = alarmTime;
    }

    // 启动闹钟
    public void Start()
    {
        while (DateTime.Now < _alarmTime)
        {
          
            OnTick(new TickEventArgs { CurrentTime = DateTime.Now });

        
            Thread.Sleep(1000);
        }


        OnAlarm(new AlarmEventArgs { AlarmMessage = "时间到了！该起床了！" });
    }

    protected virtual void OnTick(TickEventArgs e)
    {
        Tick?.Invoke(this, e);
    }

    protected virtual void OnAlarm(AlarmEventArgs e)
    {
        Alarm?.Invoke(this, e);
    }
}

class Program
{
    static void Main(string[] args)
    {

        DateTime alarmTime = DateTime.Now.AddSeconds(10);

       
        AlarmClock alarmClock = new AlarmClock(alarmTime);

        alarmClock.Tick += (sender, e) =>
        {
            Console.WriteLine($"嘀嗒：当前时间 {e.CurrentTime:HH:mm:ss}");
        };

        alarmClock.Alarm += (sender, e) =>
        {
            Console.WriteLine(e.AlarmMessage);
        };

        Console.WriteLine($"闹钟已启动，将在 {alarmTime:HH:mm:ss} 响铃。");
        alarmClock.Start();
    }
}